home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / jwpsrc.zip / MISC.C < prev    next >
C/C++ Source or Header  |  1993-03-31  |  43KB  |  1,286 lines

  1. /* Copyright (C) Stephen Chung, 1991-1993.  All rights reserved. */
  2.  
  3. #include "jwp.h"
  4.  
  5. #include "idm.h"
  6.  
  7. #include <dir.h>
  8. #include <sys/stat.h>
  9.  
  10. static long int percent, ohpercent;
  11. static int HeaderNum;
  12. static BOOL LeftRight;
  13.  
  14. static char *filespec = NULL;
  15. static KANJI far *criteria[NRSUMMARIES] = { NULL, NULL, NULL, NULL, NULL };
  16. static char *FileInfoName;
  17.  
  18. extern BOOL Dialogs3D;
  19.  
  20. #define PARENTDIR   "<Go Up>"
  21. #define DRIVECHAR   '['
  22. #define FILENAMELEN 15
  23. #define NRQUICKFILE 4
  24.  
  25. #define NRPROGS     4
  26.  
  27.  
  28. static char *QuickFiles[NRQUICKFILE];
  29.  
  30. #define TPLBLOCKSIZE    5
  31.  
  32. typedef struct {
  33.     char far *filename;
  34.     KANJI far *desc;
  35. } TPLFILE;
  36.  
  37. char far *TplChosen = NULL;
  38. static TPLFILE far *Templates = NULL;
  39. static int nr_templates = 0;
  40.  
  41.  
  42.  
  43. BOOL FAR PASCAL StatisticsProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  44. {
  45.     long int allocated, requests, hits, usage, overhead;
  46.     long int len;
  47.     int      num;
  48.     HWND     barhwnd;
  49.     RECT     rect;
  50.     HDC      hdc;
  51.     char     buffer[BUFSIZE];
  52.  
  53.     switch (message) {
  54.  
  55.         case WM_INITDIALOG:
  56.             FontCacheStatistics (&num, &usage, &requests, &hits);
  57.             sprintf(buffer, "%d Font Cache%s:", num, (num > 1) ? "s" : "");
  58.             SetDlgItemText(hwnd, 4201, buffer);
  59.             if (requests > 0L) {
  60.                 sprintf(buffer, "%ld / %ld  (%d%%)  %ld cached",
  61.                             hits, requests, (int) (100.0 * ((double) hits) / ((double) requests)), usage);
  62.             } else {
  63.                 sprintf(buffer, "%ld cached", usage);
  64.             }
  65.             SetDlgItemText(hwnd, 4202, buffer);
  66.  
  67.             ConvCacheStatistics (&usage, &requests, &hits);
  68.             if (requests > 0L) {
  69.                 sprintf(buffer, "%ld / %ld  (%d%%)  %ld cached",
  70.                             hits, requests, (int) (100.0 * ((double) hits) / ((double) requests)), usage);
  71.             } else {
  72.                 sprintf(buffer, "%ld cached", usage);
  73.             }
  74.             SetDlgItemText(hwnd, 4212, buffer);
  75.  
  76.             if (global.active != NULL) {
  77.                 sprintf(buffer, "%ld character%s", global.active->nr_bytes,
  78.                             (global.active->nr_bytes > 1L) ? "s" : "");
  79.                 SetDlgItemText(hwnd, 4221, buffer);
  80.  
  81.                 if (global.active->undolevels > 0) {
  82.                     sprintf(buffer, "%d change%s retained", global.active->undolevels,
  83.                             (global.active->undolevels > 1) ? "s" : "");
  84.                 } else {
  85.                     strcpy(buffer, "No changes retained");
  86.                 }
  87.                 SetDlgItemText(hwnd, 4222, buffer);
  88.             } else {
  89.                 SetDlgItemText(hwnd, 4221, "No active file");
  90.             }
  91.  
  92.             CountMemoryUsage(&allocated, &usage, &overhead);
  93.  
  94.             sprintf(buffer,"Memory Usage Efficiency (%ldK Allocated):", (allocated / 1024L) + 1);
  95.             SetDlgItemText(hwnd, 4231, buffer);
  96.  
  97.             percent = (((usage + overhead) * 100L) / allocated) + 1L;
  98.             if (percent > 100L) percent = 100L;
  99.  
  100.             ohpercent = ((usage * 100L) / allocated) + 1L;
  101.             if (ohpercent > 100L) ohpercent = 100L;
  102.  
  103.             sprintf(buffer,"%ld%%", percent);
  104.             SetDlgItemText(hwnd, 4233, buffer);
  105.  
  106.             CenterDialogBox(hwnd);
  107.  
  108.             return (TRUE);
  109.  
  110.         case WM_PAINT:
  111.             barhwnd = GetDlgItem(hwnd, 4232);
  112.             GetClientRect(barhwnd, &rect);
  113.  
  114.             len = (rect.right - 4) * percent / 100L;
  115.  
  116.             hdc = GetDC(barhwnd);
  117.             SelectObject(hdc, GetStockObject(GRAY_BRUSH));
  118.             Rectangle(hdc, 2, 2, len + 2, rect.bottom - 2);
  119.  
  120.             len = (rect.right - 4) * ohpercent / 100L;
  121.             if (Dialogs3D) {
  122.                 SelectObject(hdc, GetStockObject(BLACK_BRUSH));
  123.             } else {
  124.                 SelectObject(hdc, GetStockObject(LTGRAY_BRUSH));
  125.             }
  126.             Rectangle(hdc, 2, 2, len + 2, rect.bottom - 2);
  127.             ReleaseDC(barhwnd, hdc);
  128.             break;
  129.  
  130.         case WM_KEYDOWN:
  131.             switch (wParam) {
  132.                 case VK_ESCAPE: SendMessage(hwnd, WM_COMMAND, IDOK, 0L);
  133.                                 return (TRUE);
  134.             }
  135.             break;
  136.  
  137.         case WM_COMMAND:
  138.             switch (wParam) {
  139.                 case IDOK:
  140.                 case IDCANCEL:  EndDialog(hwnd, 0); return (TRUE);
  141.             }
  142.             break;
  143.     }
  144.  
  145.     return (FALSE);
  146. }
  147.  
  148.  
  149.  
  150. BOOL FAR PASCAL SummaryProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  151. {
  152.     switch (message) {
  153.         case WM_INITDIALOG: {
  154.             int i, len;
  155.             FILEOPTIONS *f, *f1;
  156.             KANJI buffer[MAXLINELEN];
  157.  
  158.             /* Set the type and mode-change icon of the Jedit controls */
  159.  
  160.             f1 = global.active;
  161.  
  162.             for (i = 0; i < NRSUMMARIES; i++) {
  163.                 SendDlgItemMessage(hwnd, 4201 + i, EM_SETRECT, GetDlgItem(hwnd, 4211), 0L);
  164.                 f = (FILEOPTIONS *) SendDlgItemMessage(hwnd, 4201 + i, EM_GETHANDLE, 0, 0L);
  165.  
  166.                 if (f1 != NULL && f1->summary[i] != NULL) {
  167.                     kanjicpy(buffer, f1->summary[i]);
  168.                     SendDlgItemMessage(hwnd, 4201 + i, EM_REPLACESEL, 0, (LONG) buffer);
  169.                 } else {
  170.                     buffer[0] = 0;
  171.                 }
  172.                 if (i == 0) {
  173.                     len = kanjilen(buffer);
  174.                     SendDlgItemMessage(hwnd, 4211, EM_SETHANDLE, f->hwnd, 0L);  /* icon-change */
  175.                 }
  176.             }
  177.  
  178.             if (len > 0) SendDlgItemMessage(hwnd, 4201, EM_SETSEL, len, MAKELONG(0, len - 1));
  179.             SetFocus(GetDlgItem(hwnd, 4201));
  180.             CenterDialogBox(hwnd);
  181.             return (TRUE);
  182.         }
  183.  
  184.         case WM_PAINT: {
  185.             int i;
  186.             HDC hdc;
  187.             PAINTSTRUCT ps;
  188.  
  189.             hdc = BeginPaint(hwnd, &ps);
  190.  
  191.             for (i = 0; i < NRSUMMARIES; i++) DrawBoundingBox(hwnd, hdc, 4201 + i);
  192.  
  193.             EndPaint(hwnd, &ps);
  194.             return (TRUE);
  195.         }
  196.  
  197.         case WM_COMMAND: {
  198.             int i, j, len;
  199.             KANJI far *kp;
  200.             UNIT far *up;
  201.  
  202.             switch (wParam) {
  203.                 case IDOK:
  204.                     if (global.active != NULL) {
  205.                         for (i = 0; i < NRSUMMARIES; i++) {
  206.                             up = (UNIT far *) SendDlgItemMessage(hwnd, 4201 + i, EM_GETLINE, 0, 0L);
  207.                             len = unitlen(up);
  208.  
  209.                             if (len <= 0) {
  210.                                 if (global.active->summary[i] != NULL) {
  211.                                     FreeBlock(global.active->summary[i]);
  212.                                     global.active->summary[i] = NULL;
  213.                                 }
  214.                             } else {
  215.                                 kp = global.active->summary[i];
  216.                                 if (kp == NULL) {
  217.                                     kp = (KANJI far *) BlockAlloc((len + 5) * sizeof(KANJI));
  218.                                 } else if ((SegHeapGetSize(kp) / sizeof(KANJI)) < len + 5) {
  219.                                     FreeBlock(kp);
  220.                                     kp = (KANJI far *) BlockAlloc((len + 5) * sizeof(KANJI));
  221.                                 }
  222.                                 for (j = 0; up[j].kanji; j++) kp[j] = up[j].kanji;
  223.                                 kp[j] = 0;
  224.                                 global.active->summary[i] = kp;
  225.                             }
  226.                         }
  227.                     }
  228.                     EndDialog(hwnd, TRUE);
  229.                     return (TRUE);
  230.  
  231.                 case IDCANCEL:
  232.                     EndDialog(hwnd, FALSE);
  233.                     return (TRUE);
  234.             }
  235.             break;
  236.         }
  237.     }
  238.     return (FALSE);
  239. }
  240.  
  241.  
  242.  
  243. BOOL FAR PASCAL EditHeaderProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  244. {
  245.     switch (message) {
  246.         case WM_INITDIALOG: {
  247.             int i, len;
  248.             FILEOPTIONS *f;
  249.             KANJI far *kp;
  250.  
  251.             if (LeftRight) {
  252.                 switch (HeaderNum) {
  253.                     case 0: SetWindowText(hwnd, "Edit Left Page Header"); break;
  254.                     case 1: SetWindowText(hwnd, "Edit Right Page Header"); break;
  255.                     case 2: SetWindowText(hwnd, "Edit Left Page Footer"); break;
  256.                     case 3: SetWindowText(hwnd, "Edit Right Page Footer"); break;
  257.                 }
  258.             }